<template>
    <a-modal
        :title="title"
        :width="450"
        :body-style="{height: '150px'}"
        @cancel="close"
        :visible="visible">

        <a-date-picker
            v-model="year"
            type="year"
            mode="year"
            format="YYYY"
            placeholder="请选择年度"
            @panelChange="changeYear"
            style="width: 100%;"/>
        <template slot="footer">
            <a-button @click="close">{{ $t('m.common.button.close') }}</a-button>
            <a-button type="primary" @click="yearOk">{{ $t('m.common.button.ok') }}</a-button>
        </template>
    </a-modal>
</template>

<script>
import store from '@/store/'
import YchConstant from "../../api/YchConstant";
import { axios } from '@/utils/request'
import moment from 'moment'

export default {
name: 'YearSelect',
data() {
    return {
        moment,
        title: this.$t('m.system.portal.entity.switchYear'),
        visible: false,
        year: store.getters.year,
        lang: YchConstant.LANG,
    }
},
methods: {

    panelChangeOne(value) {
        //console.log(value)
        this.year = value
    },
    changeYear(year){
        this.year = year
    },
    async yearOk() {
        const res = await axios({
            url: YchConstant.SPZX_OA + '/nkRsNd/edit',
            method:'get',
            params: {
                fnd: this.year.format('YYYY'),
                fsfxz: '是'
            },
            url_1:'',
            url_2:'outside',
        })
        if(res.code == 200){
            this.close()
            this.$message.success('修改成功！即将刷新页面...')
            // this.year = year
            this.$router.go(0);
        } else {
            this.$message.warning(res.message)
        }
    },
    async show() {
        const res = await axios({
            url: YchConstant.SPZX_OA + '/nkRsNd/hqndList',
            method:'get',
            params: {},
            url_1:'',
            url_2:'outside',
        })
        if(res.code == 200){
            this.year = moment(res.result)
        }
        this.visible = true
    },
    close() {
        this.visible = false
    },
}
}
</script>

